# -*- coding: utf-8 -*-

# Scrapy settings for DynamicSpider project
#
# For simplicity, this file contains only settings considered important or
# commonly used. You can find more settings consulting the documentation:
#
#     https://doc.scrapy.org/en/latest/topics/settings.html
#     https://doc.scrapy.org/en/latest/topics/downloader-middleware.html
#     https://doc.scrapy.org/en/latest/topics/spider-middleware.html

BOT_NAME = 'DynamicSpider'

SPIDER_MODULES = ['DynamicSpider.spiders']
NEWSPIDER_MODULE = 'DynamicSpider.spiders'


# Crawl responsibly by identifying yourself (and your website) on the user-agent
#USER_AGENT = 'DynamicSpider (+http://www.yourdomain.com)'

# Obey robots.txt rules
ROBOTSTXT_OBEY = False

# Configure maximum concurrent requests performed by Scrapy (default: 16)
#CONCURRENT_REQUESTS = 32

# Configure a delay for requests for the same website (default: 0)
# See https://doc.scrapy.org/en/latest/topics/settings.html#download-delay
# See also autothrottle settings and docs
#DOWNLOAD_DELAY = 3
DOWNLOAD_DELAY = 1
# The download delay setting will honor only one of:
#CONCURRENT_REQUESTS_PER_DOMAIN = 16
#CONCURRENT_REQUESTS_PER_IP = 16

# Disable cookies (enabled by default)
#COOKIES_ENABLED = False

# Disable Telnet Console (enabled by default)
#TELNETCONSOLE_ENABLED = False

# Override the default request headers:
#DEFAULT_REQUEST_HEADERS = {
#   'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
#   'Accept-Language': 'en',
#}

# Enable or disable spider middlewares
# See https://doc.scrapy.org/en/latest/topics/spider-middleware.html
#SPIDER_MIDDLEWARES = {
#    'DynamicSpider.middlewares.DynamicspiderSpiderMiddleware': 500,

#}

# Enable or disable downloader middlewares
# See https://doc.scrapy.org/en/latest/topics/downloader-middleware.html
#DOWNLOADER_MIDDLEWARES = {
#    'DynamicSpider.middlewares.DynamicspiderDownloaderMiddleware': 543,
#}

DOWNLOADER_MIDDLEWARES = {
   'DynamicSpider.middlewares.DynamicSeleniumDownloaderMiddleware': 543,
}
# Enable or disable extensions
# See https://doc.scrapy.org/en/latest/topics/extensions.html
#EXTENSIONS = {
#    'scrapy.extensions.telnet.TelnetConsole': None,
#}

# Configure item pipelines
# See https://doc.scrapy.org/en/latest/topics/item-pipeline.html
#ITEM_PIPELINES = {
#    'DynamicSpider.pipelines.DynamicspiderPipeline': 300,
#}
# 'DynamicSpider.mysql_pipelines.MysqlTwistedPipline':300,
ITEM_PIPELINES = {
   'DynamicSpider.pipelines.DynamicspiderPipeline': 400,
   #'DynamicSpider.mysql_pipelines.MysqlTwistedPipline':300,
   'DynamicSpider.NatrueMysql_pipelines.MysqlNatruePipline':200,
}


# Enable and configure the AutoThrottle extension (disabled by default)
# See https://doc.scrapy.org/en/latest/topics/autothrottle.html
#AUTOTHROTTLE_ENABLED = True
# The initial download delay
#AUTOTHROTTLE_START_DELAY = 5
# The maximum download delay to be set in case of high latencies
#AUTOTHROTTLE_MAX_DELAY = 60
# The average number of requests Scrapy should be sending in parallel to
# each remote server
#AUTOTHROTTLE_TARGET_CONCURRENCY = 1.0
# Enable showing throttling stats for every response received:
#AUTOTHROTTLE_DEBUG = False

# Enable and configure HTTP caching (disabled by default)
# See https://doc.scrapy.org/en/latest/topics/downloader-middleware.html#httpcache-middleware-settings
#HTTPCACHE_ENABLED = True
#HTTPCACHE_EXPIRATION_SECS = 0
#HTTPCACHE_DIR = 'httpcache'
#HTTPCACHE_IGNORE_HTTP_CODES = []
#HTTPCACHE_STORAGE = 'scrapy.extensions.httpcache.FilesystemCacheStorage'
################################################
#日志功能
#debug,  info,  error, warn    从低到高
#level 设置打印日志的水位线
#打印日志原则：level=info， 凡是比level的优先级高或者等，则打印日志
#线上日志一般level=error
LOG_LEVEL = "INFO"

from  datetime import datetime

import os

LOG_DIR = "log"

if not os.path.exists(LOG_DIR):
    os.makedirs(LOG_DIR)

today = datetime.now()

LOG_FILE = f"{LOG_DIR}/scrapy_{today.year}_{today.month}_{today.day}.log"

MYSQL_SETTINGS = {
   'HOST':'localhost',    #数据库地址
   'DATABASE':'jd_db',    #数据库名称
   'USER':'root',           #登陆用户名
   'PASSWORD':'123456',       #登陆密码
   'CHARSET':'utf8',          #字符编码
}
